package com.tangsm.spring.boot.strategy.demo.enums;

public enum MessageTypeEnum {
    /**
     * 未认证
     */
    SMS("sms","短信"),
    /**
     * 已认证
     */
    EMAIL("email", "电子邮箱");

    MessageTypeEnum(String code,String name){
        this.code = code;
        this.name = name;
    }

    private String code;

    private String name;

    public String getCode( ) {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName( ) {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 根据code获取name
     * @param code code
     * @return name
     */
    public static String getNameByCode(String code) {
        // 遍历枚举所有属性值
        for (MessageTypeEnum m : MessageTypeEnum.values()) {
            if (m.code.equals(code)) {
                return m.name;
            }
        }
        return "";
    }
}